package com.ruoyi.develop.goodsSaleMaterialMain.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.develop.goodsSaleMaterialMain.domain.GoodsSaleMaterialMain;
import com.ruoyi.develop.goodsSaleMaterialMain.service.IGoodsSaleMaterialMainService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 领料单Controller
 * @author lmm
 * @date 2025-08-18
 */
@RestController
@RequestMapping("/goodsSaleMaterialMain/goodsSaleMaterialMain")
public class GoodsSaleMaterialMainController extends BaseController {
    @Autowired
    private IGoodsSaleMaterialMainService goodsSaleMaterialMainService;

    /**
     * 查询领料单列表
     */
    @PreAuthorize("@ss.hasPermi('develop:GoodsSaleMaterialMain:query')")
    @GetMapping("/list")
    public TableDataInfo list(GoodsSaleMaterialMain entity) {
        startPage();
        List<GoodsSaleMaterialMain> list = goodsSaleMaterialMainService.selectList(entity);
        return getDataTable(list);
    }

    /**
     * 导出领料单列表
     */
    @PreAuthorize("@ss.hasPermi('develop:GoodsSaleMaterialMain:export')")
    @Log(title = "领料单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GoodsSaleMaterialMain entity) {
        List<GoodsSaleMaterialMain> list = goodsSaleMaterialMainService.selectList(entity);
        ExcelUtil<GoodsSaleMaterialMain> util = new ExcelUtil<GoodsSaleMaterialMain>(GoodsSaleMaterialMain. class);
        util.exportExcel(response, list, "领料单数据");
    }

    /**
     * 获取领料单详细信息
     */
    @PreAuthorize("@ss.hasPermi('develop:GoodsSaleMaterialMain:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(goodsSaleMaterialMainService.selectById(id));
    }

    /**
     * 新增领料单
     */
    @PreAuthorize("@ss.hasPermi('develop:GoodsSaleMaterialMain:add')")
    @Log(title = "领料单", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody GoodsSaleMaterialMain entity) {
        return toAjax(goodsSaleMaterialMainService.insert(entity));
    }

    @PreAuthorize("@ss.hasPermi('develop:GoodsSaleMaterialMain:add')")
    @Log(title = "创建领料单", businessType = BusinessType.INSERT)
    @PostMapping("/addMain")
    public AjaxResult addMain(@RequestBody GoodsSaleMaterialMain entity) {
        return toAjax(goodsSaleMaterialMainService.addMain(entity));
    }
    /**
     * 修改领料单
     */
    @PreAuthorize("@ss.hasPermi('develop:GoodsSaleMaterialMain:edit')")
    @Log(title = "领料单", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody GoodsSaleMaterialMain entity) {
        return toAjax(goodsSaleMaterialMainService.update(entity));
    }

    /**
     * 删除领料单
     */
    @PreAuthorize("@ss.hasPermi('develop:GoodsSaleMaterialMain:remove')")
    @Log(title = "领料单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(goodsSaleMaterialMainService.deleteByIds(ids));
    }
}
